#include "fanc.h"

void InitContact()
{
	cout << "***************************" << endl;
	cout << "*****  1、添加联系人  *****" << endl;
	cout << "*****  2、显示联系人  *****" << endl;
	cout << "*****  2、显示联系人  *****" << endl;
	cout << "*****  3、删除联系人  *****" << endl;
	cout << "*****  4、查找联系人  *****" << endl;
	cout << "*****  5、修改联系人  *****" << endl;
	cout << "*****  6、清空联系人  *****" << endl;
	cout << "*****  0、退出联系人  *****" << endl;
	cout << "***************************" << endl;
	
}

int Add_contacter(struct Cont cont[],int count)
{

	cout << "请输入姓名：" << endl;
	cin >> cont[count].name;
	cout << "请输入性别：" << endl;
	cin >> cont[count].sex;
	cout << "请输入年龄：" << endl;
	cin >> cont[count].age;
	cout << "请输入电话：" << endl;
	cin >> cont[count].tel;
	cout << "请输入地址：" << endl;
	cin >> cont[count].address;
	count++;

	cout << "添加成功!" << endl;
	return count;
}

void Show_contacter(struct Cont cont[] , int count)
{
	cout << "姓名\t\t" << "性别\t" << "年龄\t" << "电话\t\t" << "地址" << endl;
	for (int i = 0; i < count; i++)
	{
		cout << cont[i].name << '\t' << cont[i].sex << '\t' << \
			cont[i].age << '\t' << cont[i].tel << '\t' << cont[i].address << endl;
	}
	
}

int Delete_contacter(struct Cont* cont, int count)
{
	string name;
	int flag = true;

	cout << "输入要删除的人";
	cin >> name;

	for (int i = 0; i < count; i++)
	{
		if (name == (cont+i)->name)
		{
			for (int j = i; j < count - i; j++)
			{
				*(cont+j) = *(cont+j+1);
			}
			cout << "删除成功";
			flag = false;
			break;
		}
		
	}
	if (flag)
	{
		cout << "查无此人";
	}
	count--;
	return count;

}
//0
//1
//2
//3
//4

void Search_contacter(struct Cont cont[],int count)
{
	string name;
	
	cout << "输入要查找的人";
	cin >> name;
	int num = 0;

	for (int i = 0; i < count; i++)
	{
		if (name == cont[i].name)
		{
			num++;
			if (num == 1)
			{
				cout << "姓名\t\t" << "性别\t" << "年龄\t" << "电话\t\t" << "地址" << endl;
			}
			cout << cont[i].name << '\t' << cont[i].sex << '\t' << \
				cont[i].age << '\t' << cont[i].tel << '\t' << cont[i].address << endl;
			
		}

	}
	if (!num)
	{
		cout << "查无此人";
	}
}

void Mod_contacter(struct Cont cont[], int count)
{
	string name;
	int flag = true;
	cout << "输入要修改的人";
	cin >> name;

	int num = 0;

	for (int i = 0; i < count; i++)
	{
		if (name == cont[i].name)
		{
			flag = false;

			cout << "请输入修改的姓名：" << endl;
			cin >> cont[i].name;
			cout << "请输入修改的性别：" << endl;
			cin >> cont[i].sex;
			cout << "请输入修改的年龄：" << endl;
			cin >> cont[i].age;
			cout << "请输入修改的电话：" << endl;
			cin >> cont[i].tel;
			cout << "请输入修改的地址：" << endl;
			cin >> cont[i].address;
			count++;
		}

	}
	if (flag)
	{
		cout << "查无此人";
	}
}

int Clear_contacter(int count)
{
	cout << "确认清空吗？确认请按1，按0取消" << endl;
	int flag = 0;
	cin >> flag;
	if (flag == 1)
	{
		count = 0;
	}

	return count;
}
